package com.ruoyi.huoyun.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.huoyun.business.domain.WaybillInfo;
import com.ruoyi.huoyun.business.service.IWaybillInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运单详情Controller
 * 
 * @author mj
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/business/waybill")
public class WaybillInfoController extends BaseController
{
    @Autowired
    private IWaybillInfoService waybillInfoService;

    /**
     * 查询运单详情列表
     */
    @PreAuthorize("@ss.hasPermi('business:waybill:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaybillInfo waybillInfo)
    {
        startPage();
        List<WaybillInfo> list = waybillInfoService.selectWaybillInfoList(waybillInfo);
        return getDataTable(list);
    }

    /**
     * 导出运单详情列表
     */
    @PreAuthorize("@ss.hasPermi('business:waybill:export')")
    @Log(title = "运单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WaybillInfo waybillInfo)
    {
        List<WaybillInfo> list = waybillInfoService.selectWaybillInfoList(waybillInfo);
        ExcelUtil<WaybillInfo> util = new ExcelUtil<WaybillInfo>(WaybillInfo.class);
        util.exportExcel(response, list, "运单详情数据");
    }

    /**
     * 获取运单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:waybill:query')")
    @GetMapping(value = "/{waybillId}")
    public AjaxResult getInfo(@PathVariable("waybillId") String waybillId)
    {
        return AjaxResult.success(waybillInfoService.selectWaybillInfoByWaybillId(waybillId));
    }

    /**
     * 新增运单详情
     */
    @PreAuthorize("@ss.hasPermi('business:waybill:add')")
    @Log(title = "运单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaybillInfo waybillInfo)
    {
        String waybillId = System.currentTimeMillis() + "";
        waybillInfo.setWaybillId(waybillId);
        return toAjax(waybillInfoService.insertWaybillInfo(waybillInfo));
    }

    /**
     * 修改运单详情
     */
    @PreAuthorize("@ss.hasPermi('business:waybill:edit')")
    @Log(title = "运单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaybillInfo waybillInfo)
    {
        return toAjax(waybillInfoService.updateWaybillInfo(waybillInfo));
    }

    /**
     * 删除运单详情
     */
    @PreAuthorize("@ss.hasPermi('business:waybill:remove')")
    @Log(title = "运单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{waybillIds}")
    public AjaxResult remove(@PathVariable String[] waybillIds)
    {
        return toAjax(waybillInfoService.deleteWaybillInfoByWaybillIds(waybillIds));
    }
}
